package com.fuxue.controller.user;

import com.fuxue.dto.*;
import com.fuxue.result.PageResult;
import com.fuxue.result.Result;
import com.fuxue.service.ForumService;
import com.fuxue.vo.ALLDetialsVO;
import com.fuxue.vo.KnowledgeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("userForumController")
@RequestMapping("/users/user/forum")
@Slf4j
@Api(tags = "用户端论坛有关页面")
public class ForumController {
    @Autowired
    private ForumService forumService;

    @GetMapping("/question")
    @ApiOperation("论坛问答贴分页查询")
    private Result<PageResult> AllCanSee(ForumDTO forumDTO)
    {
        log.info("论坛问答贴分页查询，参数为：{}",forumDTO);
        PageResult pageResult = forumService.pageQuery(forumDTO);
        return Result.success(pageResult);
    }

    /*
    知识贴
    */
    @GetMapping("/answer")
    @ApiOperation("知识贴分页查询")
    private Result<PageResult> Answer(ForumDTO forumDTO)
    {
        log.info("知识贴分页查询，参数为：{}",forumDTO);
        PageResult pageResult = forumService.pageAnswerQuery(forumDTO);
        return Result.success(pageResult);
    }

    /*
    得到论坛的详细内容
     */
    @GetMapping("/allDetials")
    @ApiOperation("问答贴详情")
    private Result<ALLDetialsVO>GetAllDetials(Integer id)
    {
        log.info("问答贴详细内容，参数为：{}",id);
        ALLDetialsVO allDetialsVO = new ALLDetialsVO();
        allDetialsVO = forumService.getALL(id);
        return Result.success(allDetialsVO);
    }
    @GetMapping("/answerDetials")
    @ApiOperation("知识贴详情")
    private Result<KnowledgeVO>GetAnswerDetails(Integer id)
    {
        log.info("知识贴详情，参数为：{}",id);
        KnowledgeVO knowledgeVO = new KnowledgeVO();
        knowledgeVO = forumService.getKnowledge(id);
        return Result.success(knowledgeVO);
    }
/*
收藏功能实现
 */
    /*
    向收藏表中插入数据
     */
    @PostMapping("/newCollect")
    @ApiOperation("收藏插入功能")
    private Result newCollect(CollectionDTO collectionDTO)
    {
        log.info("收藏插入功能，参数为：{}",collectionDTO);
        forumService.newCollect(collectionDTO);
        return Result.success();
    }
    /*
    收藏问答贴分页查询
     */
    @GetMapping("/questionCollection")
    @ApiOperation("收藏问答贴分页查询")
    private Result<PageResult> QuestionCollection(CollectionPageDTO collectionPageDTO)
    {
        log.info("收藏问答贴分页查询，参数为：{}",collectionPageDTO);
        PageResult pageResult = forumService.questionCollectionPageQuery(collectionPageDTO);
        return Result.success(pageResult);
    }
    /*
    收藏知识贴分页查询
     */
    @GetMapping("/AnswerCollection")
    @ApiOperation("收藏知识贴分页查询")
    private Result<PageResult> AnswerCollection(CollectionPageDTO collectionPageDTO)
    {
        log.info("收藏知识贴分页查询，参数为：{}",collectionPageDTO);
        PageResult pageResult = forumService.AnswerCollectionPageQuery(collectionPageDTO);
        return Result.success(pageResult);
    }
}
